package com.oceanread.cn.controller;

import com.alibaba.fastjson.JSONObject;
import com.oceanread.cn.entity.Drillhole2;
import com.oceanread.cn.entity.Query;
import com.oceanread.cn.service.IDrillhole2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Drillhole2")
@CrossOrigin()
@Api(value = "", tags = {"2.1.1-钻孔材质"})
public class Drillhole2Controller {
    @Autowired
    private IDrillhole2Service iDrillhole2Service;

    @GetMapping("/getall")
    public List<Drillhole2> getAll() {
        return iDrillhole2Service.getall();
    }

    @PostMapping("/query")
    public List<Drillhole2> query(@RequestBody Query query){
        return iDrillhole2Service.query(query.getKey(),query.getValue());
    }
    @GetMapping("/query1")
    public JSONObject query1(@RequestParam(name = "page", required = true, defaultValue = "1") int page,
                             @RequestParam(name = "size", required = true, defaultValue = "10") int size,
                             @RequestParam(name = "key") String key,
                             @RequestParam(name = "value") String value
    ) {
        JSONObject object = new JSONObject();
        object.put("data", iDrillhole2Service.query1(key, value, page, size));
        object.put("total", iDrillhole2Service.getnumquery(key, value));
        return object;
    }
//    @PostMapping("/query2")
//    public List<Drillhole2> query2(@RequestBody Query query){
//        return iDrillhole2Service.query2(query.getKey(),query.getValue(),query.getKey2(),query.getValue2());
//    }
    @GetMapping("/query2")
    public JSONObject query2(@RequestParam(name = "page", required = true, defaultValue = "1") int page,
                             @RequestParam(name = "size", required = true, defaultValue = "10") int size,
                             @RequestParam(name = "key") String key,
                             @RequestParam(name = "value") String value,
                             @RequestParam(name = "key2") String key2,
                             @RequestParam(name = "value2") String value2
    ) {
        JSONObject object = new JSONObject();
        object.put("data", iDrillhole2Service.query2(key, value,key2, value2, page, size));
        object.put("total", iDrillhole2Service.getnumquery2(key, value,key2, value2));
        return object;
    }
    @GetMapping("/query2json")
    public JSONObject query2json(
            @RequestParam(name = "key") String key,
            @RequestParam(name = "value") String value,
            @RequestParam(name = "key2") String key2,
            @RequestParam(name = "value2") String value2
    ) {
        JSONObject object = new JSONObject();
        object.put("data", iDrillhole2Service.query2json(key, value,key2, value2));
        return object;
    }

    @PostMapping("/update")
    public Integer update1(@RequestBody Drillhole2 drillhole2) {
        return iDrillhole2Service.update(drillhole2);
    }

    @ApiOperation(value = "新增材质")
    @PostMapping("/insert")
    public Integer insert1(@RequestBody Drillhole2 drillhole2) {
        return iDrillhole2Service.insert(
                drillhole2.getPrjCode(),drillhole2.getPrjID(),drillhole2.getOrder(),
                drillhole2.getAltitude(),drillhole2.getStart(),drillhole2.getThickness(),
                drillhole2.getMaterial(),drillhole2.getMaterial0()
        );
    }
    @GetMapping("/delete")
    public Integer delete1(@RequestParam(name = "SYSID") int SYSID) {
        return iDrillhole2Service.delete(SYSID);
    }
}
